﻿using System;
using Duo1JHttpServer.Framework.Enum;

namespace Duo1JHttpServer.Framework.Utils
{
    public static class EnumUtils
    {
        /// <summary>
        /// 根据请求方法字符串获取请求方法枚举
        /// </summary>
        /// <param name="method">请求方法string</param>
        public static RequestType GetRequestType(string method)
        {
            switch (method.ToUpper())
            {
                case "GET":
                    return RequestType.Get;
                case "POST":
                    return RequestType.Post;
                default:
                    ConsoleUtils.WriteRedLine($"Unknown RequestType: {method}");
                    return RequestType.Unknown;
            }
        }

        /// <summary>
        /// 根据xml节点属性名获取对应映射器属性类型
        /// </summary>
        /// <param name="attrName"></param>
        public static MapperAttrType GetMapperAttrType(string attrName)
        {
            switch (attrName.ToUpper())
            {
                case "CLASS":
                    return MapperAttrType.Class;
                case "URL":
                    return MapperAttrType.Url;
                case "ASSEMBLY":
                    return MapperAttrType.Assembly;
                default:
                    ConsoleUtils.WriteRedLine($"Unknown AttrType: {attrName}");
                    return MapperAttrType.Unknown;
            }
        }

        /// <summary>
        /// 根据xml节点属性名获取对应过滤器属性类型
        /// </summary>
        /// <param name="attrName"></param>
        public static FilterAttrType GetFilterAttrType(string attrName)
        {
            switch (attrName.ToUpper())
            {
                case "CLASS":
                    return FilterAttrType.Class;
                case "URL":
                    return FilterAttrType.Url;
                case "ASSEMBLY":
                    return FilterAttrType.Assembly;
                default:
                    ConsoleUtils.WriteRedLine($"Unknown AttrType: {attrName}");
                    return FilterAttrType.Unknown;
            }
        }
    }
}